/*
 * Copyright (c) 2017 Solidwang. All Rights Reserved
 */
package com.solid4j.auth.page;

import java.io.Serializable;
import java.util.List;

/**
 * @author: solidwang
 * @date: 17/4/28
 * 分页bean
 */
public class Page<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    //每页显示条数
    private Integer pageSize = 10;
    //总条数
    private Integer totalCount = 0;
    //总页数
    private Integer totalPage = 0;
    //当前页
    private Integer currentPage = 1;
    //起始位置
    private Integer startIndex = 0;
    //查询条件
    private String condition;
    //对象集合
    private List<T> objList;
    //排序
    private String orderBy;
    //查询对象
    private String objName;
    //查询字段
    private String queryFields;

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getTotalPage() {
        totalPage = totalCount % pageSize == 0 ? (totalCount / pageSize) : (totalCount / pageSize + 1);
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        if (currentPage <= 0) currentPage = 1;
        this.currentPage = currentPage;
    }

    public Integer getStartIndex() {
        startIndex = (this.currentPage - 1) * this.pageSize;
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    public String getCondition() {
        return condition;
    }

    public void setCondition(String condition) {
        this.condition = condition;
    }

    public List<T> getObjList() {
        return objList;
    }

    public void setObjList(List<T> objList) {
        this.objList = objList;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public String getObjName() {
        return objName;
    }

    public void setObjName(String objName) {
        this.objName = objName;
    }

    public String getQueryFields() {
        return queryFields;
    }

    public void setQueryFields(String queryFields) {
        this.queryFields = queryFields;
    }

    @Override
    public String toString() {
        return "Page{" +
                "pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", currentPage=" + currentPage +
                ", startIndex=" + startIndex +
                ", condition='" + condition + '\'' +
                ", objList=" + objList +
                ", orderBy='" + orderBy + '\'' +
                ", objName='" + objName + '\'' +
                ", queryFields='" + queryFields + '\'' +
                '}';
    }
}
